<extend name="Base/common"/>
<!--<script type="text/javascript" src="/SG_Shopwechat/Public/Home/js/iscroll.js"></script>-->
<block name="TITLE"><title>我的待报价商品</title></block>
<block name="body" >
    <header data-am-widget="header" class="am-header am-header-default am-header-fixed">
        <div class="am-header-left am-header-nav">
            <a href="{:U('Login/index')}" class="">
                <i class="am-header-icon am-icon-home" style="font-size: 40px;"></i>
            </a>
        </div>
        <h1 class="am-header-title">
            <a href="#title-link" class="">
                &nbsp;{$title}
            </a>
        </h1>

    </header>
    <div class="  am-list-news-bd" >
        <empty name="_goods">
            暂时没有商品
            <else/>
            <table  class="am-table am-table-striped " style="width:100%;">
                <thead style="">
                <tr>
                    <th></th>
                    <th>商品名</th>
                    <th>规格</th>
                    <th>总件数</th>
                    <th>已报价</th>
                    <th>报价</th>
                </tr>
                </thead>
                <volist name="_goods" id="pro">
                    <tr>
                        <td ></td>
                        <td>{$pro.proName}</td>
                        <td>{$pro.spec}</td>
                        <td>{$pro.number}</td>
                        <td>
                            <if condition="$pro['reported'] eq 1">
                                <span class="am-text-success am-icon am-icon-check"></span>
                            </if>
                            <if condition="$pro['reported'] eq 0">
                                <span class="am-text-danger am-icon am-icon-clock-o"></span>
                            </if>
                        </td>
                        <td>
                            <if condition="$pro['reported'] eq 1">
                                <a data-batch="{$pro.batch}" data-pid="{$pro.pid}" data-price="{$pro.oldprice}" data-mark="{$pro.oldmark}" class="am-btn  am-btn-default am-btn-sm am-radius myreport">我的报价</a>
                                <a data-batch="{$pro.batch}" data-pid="{$pro.pid}" class="am-btn  am-btn-primary am-btn-sm am-radius report">新报价</a>
                            </if>
                            <if condition="$pro['reported'] eq 0">
                                <a data-batch="{$pro.batch}" data-pid="{$pro.pid}" class="am-btn  am-btn-primary am-btn-sm am-radius report">回复报价</a>
                            </if>

                        </td>
                    </tr>
                </volist>
            </table>
        </empty>
        <div class="am-modal am-modal-confirm" tabindex="-1" id="mymodal">
            <div class="am-modal-dialog">
                <div class="am-modal-hd am-text-xl">回复报价
                    <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
                </div>
                <div class="am-modal-bd">
                    <form id="reportForm" >
                        <input type="hidden" name="batch" id="batch">
                        <input type="hidden" name="pid" id="pid">
                        <div class="am-form-group">
                            <label for="price" class="am-align-left">报价</label>
                            <input type="number" class="am-form-field" name="price" id="price" placeholder="" required>
                        </div>
                        <div class="am-form-group">
                            <label for="mark" class="am-align-left">备注</label>
                            <input type="text" class="am-form-field" name="mark" id="mark" placeholder="" />
                        </div>
                    </form>
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-cancel>取消</span>
                    <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                </div>
            </div>
        </div>
        <div class="am-modal am-modal-confirm" tabindex="-1" id="oldreport">
            <div class="am-modal-dialog">
                <div class="am-modal-hd am-text-xl">回复报价
                    <a href="javascript: void(0)" class="am-close am-close-spin" data-am-modal-close>&times;</a>
                </div>
                <div class="am-modal-bd">
                    <div class="am-form-group">
                        <label for="oldprice" class="am-align-left">报价</label>
                        <input type="number" class="am-form-field" readonly name="oldprice" id="oldprice" placeholder="" required>
                    </div>
                    <div class="am-form-group">
                        <label for="oldmark" class="am-align-left">备注</label>
                        <input type="text" class="am-form-field" readonly name="oldmark" id="oldmark" placeholder="" />
                    </div>
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-confirm>确定</span>
                </div>
            </div>
        </div>
        <div class="am-modal am-modal-alert am-modal-active" tabindex="-1" id="myalert">
            <div class="am-modal-dialog">
                <div class="am-modal-hd">
                    <span id="errTitle"></span>
                </div>
                <div class="am-modal-bd">
                    <span id="errContent"></span>
                </div>
                <div class="am-modal-footer">
                    <span class="am-modal-btn" data-am-modal-confirm> 确定</span>
                </div>
            </div>
        </div>
    </div>
</block>
<block name="script">
    <script type="text/javascript">
        $(function(){
            var alertTitle = $("#errTitle");
            var alertContent = $("#errContent");
            $('.report').click(function(){
                var btn = $(this);
                var batch = $(this).data('batch');
                var pid = $(this).data('pid');
                $("#batch").val(batch) ;
                $("#pid").val(pid);

                $("#mymodal").modal({
                    relatedTarget: this,
                    onConfirm: function() {
                        var url = '{:U('givereport')}';
                        if($("#price").val() == ""||$("#price").val()==undefined){
                            $("#errTitle").html("提示！")
                            $("#errContent").html("请输入您的报价");
                            $("#myalert").modal();
                            return false;
                        }
                        $.ajax({
                            type: "POST",
                            url:url,
                            data:$('#reportForm').serialize(),
                            async: false,
                            error: function(request) {
                                alert(request);
                            },
                            success: function(data) {
                                if(data == 1||data =="1"){
                                    alertTitle.html("提示");
                                    alertContent.html("报价已回复");
                                    $("#myalert").modal({
                                        relatedTarget: this,
                                        onConfirm: function() {
                                            window.location.reload();
                                        }
                                    });
                                }else if(data == 2||data =="2"){
                                    alertTitle.html("提示");
                                    alertContent.html("该商品已被采购");
                                    $("#myalert").modal({
                                        relatedTarget: this,
                                        onConfirm: function() {
                                            window.location.reload();
                                        }
                                    });
                                }else{
                                    alertTitle.html("提示");
                                    alertContent.html("错误");
                                    $("#myalert").modal({
                                        relatedTarget: this,
                                        onConfirm: function() {
                                            window.location.reload();
                                        }
                                    });
                                }
                            }
                        });


                    },
                    onCancel: function() {
                    }
                });
            });
            $(".myreport").click(function(){
                var oldprice = $(this).data("price");
                var oldmark = $(this).data("mark");
                $("#oldprice").val(oldprice);
                $("#oldmark").val(oldmark);
                $("#oldreport").modal();
            });
        });
    </script>
</block>
